package cn.tedu._06springaop.egaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggerAspect {
    @Pointcut(value="execution(public boolean cn.tedu._06springaop.egaop.CartServiceImpl.addCart(..))")
    public void doTime(){
    }
    @Around(value="doTime()")
    public Object aroundMethod(ProceedingJoinPoint joinPoint){
        boolean result = true;
        try{
            System.out.println("开始添加购物车");
            result = (boolean) joinPoint.proceed();
            if(result){
                System.out.println("添加购物车成功");
            }else{
                System.out.println("添加购物车失败");
            }
        }catch(Throwable e){
            throw new RuntimeException(e);
        }finally{
            System.out.println("操作完成");
        }
        return result;
    }
}
